package view.rules;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;


import net.miginfocom.swing.MigLayout;

public class SpelledOutPanelB extends JPanel{
	
	TriggerPanel triggerPanel;
	SubmitPanel submitPanel;
	private JPanel secondPanel;
	private JPanel thirdPanel;
	private JPanel forthPanel;
	private JPanel comPanel;
	private JButton importFromMSButton;
	private JLabel layerLabel;
	private JSpinner layerSpinner;
	private JLabel layerNameLabel;
	private JTextField layerNameTextField;
	private JButton addLayerButton;
	private JButton deleteLayerButton;
	private JButton moveLayerButton;
	private JButton addRowButton;
	private JButton addColumnButton;
	private JButton moveRowButton;
	private JButton moveColumnButton;
	private JTable table;
	private JLabel commentLabel;
	private JTextArea commentArea;
	private JScrollPane tableScroll;
	TriggerButtonListener okListener;
	

    DefaultTableModel sampleMeanModel;
	
	public SpelledOutPanelB(){
		this.setLayout(new MigLayout());
		initComponent();
		addComponent();
	}

	private void initComponent() {
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		
		triggerPanel = new TriggerPanel();
		
		secondPanel = new JPanel();
		secondPanel.setLayout(new MigLayout());
		
		importFromMSButton = new JButton("Import Table Layer from MS Word File");
		layerLabel = new JLabel("Layer");
		SpinnerModel sm = new SpinnerNumberModel(0, 0, 100, 1);
		layerSpinner = new JSpinner(sm);
		layerSpinner.setMinimumSize(new Dimension(100, 20));
		layerNameLabel = new JLabel("Layer Name:");
		layerNameTextField = new JTextField(70);
		addLayerButton = new JButton("Add Layer");
		deleteLayerButton = new JButton("Delete Layer");
		moveLayerButton = new JButton("Move Layer");
		
		comPanel = new JPanel();
		comPanel.setLayout(new MigLayout());
		
		thirdPanel = new JPanel();
		thirdPanel.setLayout(new MigLayout());
		thirdPanel.setPreferredSize(new Dimension(150, 400));
		
		addRowButton = new JButton("Add Row");
		addColumnButton = new JButton("Add Column");
		addColumnButton.setMinimumSize(new Dimension(50, 20));
		moveRowButton = new JButton("Move Row");
		moveRowButton.setEnabled(false);
		moveColumnButton = new JButton("Move Column");
		moveColumnButton.setEnabled(false);
		
		forthPanel = new JPanel();
		forthPanel.setLayout(new MigLayout());
		forthPanel.setBorder(BorderFactory.createTitledBorder(""));
		forthPanel.setMinimumSize(new Dimension(1000, 300));
		
		String[] columns = { "Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6", "Column 7", "Column 8", "Column 9", "Column 10"};
        Object[][] data = {{"x", "Layer1", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"},
                           {"x", "Layer2", "fsf", "sdsdsdfsd", "asdsdsad", "sfasfsf", "sfsfsdf", "asdsdsad", "sfasfsf", "sfsfsdf"}};
		
		table = new JTable(data, columns);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setFocusable(false);
        table.setRowSelectionAllowed(false);
        table.setEnabled(false);
        
        tableScroll = new JScrollPane(table);
        tableScroll.setPreferredSize(new Dimension(700, 300));
        
        forthPanel.add(tableScroll);
        
		
		commentLabel = new JLabel("Comment:");
	    commentArea = new JTextArea();
	    commentArea.setPreferredSize(new Dimension((int)screenSize.getWidth() - 200, (int)screenSize.getHeight() - 480));
		
	    submitPanel = new SubmitPanel();
	    
	    okListener = new TriggerButtonListener();
	    triggerPanel.triggerButton.addActionListener(okListener);
		
	}
	
	private void addComponent() {
		
		add(triggerPanel, "wrap");
		add(importFromMSButton, "wrap");
		addToSecondPanel();
		add(secondPanel, "wrap");
		addToThirdPanel();
		comPanel.add(thirdPanel);
		comPanel.add(forthPanel);
		add(comPanel, "wrap");
		add(commentLabel, "wrap");
		add(commentArea, "wrap");
		add(submitPanel);
		
	}
	
	private void addToSecondPanel(){
		secondPanel.add(layerLabel);
		secondPanel.add(layerSpinner);
		secondPanel.add(layerNameLabel);
		secondPanel.add(layerNameTextField);
		secondPanel.add(addLayerButton);
		secondPanel.add(deleteLayerButton);
		secondPanel.add(moveLayerButton);
	}
	
	private void addToThirdPanel(){
		thirdPanel.add(addRowButton, "wrap");
		thirdPanel.add(addColumnButton, "wrap");
		thirdPanel.add(moveRowButton, "wrap");
		thirdPanel.add(moveColumnButton);
	}
	
}
